﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Dynamic;
using System.ComponentModel;
using CCH.Entity;

namespace CCH.DAO
{
    [DataObject(true)]
    public class linkDAO
    {
        private Entities model = new Entities();

        public IQueryable<link> Get_link_AllData(string link_type)
        {

            var data = from d in model.link
                       where d.state == "1"
                       select d;
            if (link_type != "0")
            {
                data = data.Where(o => o.link_type == link_type);
            }

           return data.OrderBy(o => o.link_order);
        }

        public IQueryable<link> Get_link_AllData(string link_type,int startRowIndex, int maximumRows)
        {
            return Get_link_AllData(link_type).Skip(startRowIndex).Take(maximumRows);
        }

        public int Get_link_AllData_Count(string link_type)
        {
            return Get_link_AllData(link_type).Count();
        }

        public link Get_link(int link_no)
        {
            return (from d in model.link where d.link_no == link_no select d).FirstOrDefault();
        }

        public void Add_link(link d)
        {
            model.link.AddObject(d);
            Update();
        }

        public void Delete_link(int link_no, int peo_uid)
        {
            link d = Get_link(link_no);
            d.state = "2";
            d.createuid = peo_uid;
            d.createtime = DateTime.Now;
            Update();
        }

        public void Update()
        {
            model.SaveChanges();
        }
    }
}
